// pages/find/index.js
var utl = require('../../utils/util.js');
var mdk = require('../../utils/md5.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    msg: '发送验证码',
    showtime: '',
    count: 60,
    tel:'',
    rcode:'',

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },
  //确认
  tjaction:function(){
    const tel = this.data.tel;
    const mcode = this.data.rcode;
    const npwd = this.data.pwd;
    const gpw = this.data.gpwd;
    if(tel.length == 0 || mcode.length == 0 || npwd.length == 0 || gpw.length == 0){
      wx.showToast({
        title: '数据不全',
        icon:'none',
        duration:2000,
      })
      return;
    }
    if(npwd != gpw){
      wx.showToast({
        title: '密码不一致',
        icon: 'none',
        duration: 2000,
      })
      return;
    }
    var secr = mdk.hexMD5(npwd);
    wx.showLoading({
      title: '请求中...',
    })
    utl.httServer('/epay_apps/password/forgetPwdA0400', { 'mobile': tel, 'captcha': mcode, "newPassWord": secr, 'confirmPassWord': secr}, (err, res) => {
      wx.hideLoading();
      if (err) {
        wx.showToast({
          title: err,
          icon: 'none',
          duration: 2000,
        })
        return;
      }
      wx.showModal({
        title: '成功',
        content: '返回登录',
        showCancel: false,
        success(res) {
          
            wx.navigateBack({
              delta: 0,
            })
        }

        })

    })

  },
  //密码
  commitPwd:function(e){
    this.setData({
      pwd:e.detail.value,
    })
  },
  //再次密码
  commitPwdAg:function(e){
    this.setData({
      gpwd:e.detail.value,
    })
  },
  //手机号
  commitTel:function(e){
    this.setData({
      tel:e.detail.value,
    })
  },
  //验证码
  commitCode:function(e){
    this.setData({
      rcode:e.detail.value
    })
  },
  //发送验证码
  sendmessage:function(){
    var tele = this.data.tel;
    if (tele == '') {
      return;
    }
    if (!utl.checkPhone(tele)) {
      wx.showToast({
        title: '手机号校验有误',
        duration: 2000,
        icon: 'none'
      })
      return;
    }
    wx.showLoading({
      title: '请求中...',
    })
    utl.httServer('/epay_apps/captcha/sendCodeA0200', { 'mobile': tele, 'smsType': '0' }, (err, res) => {
      wx.hideLoading();
      var mess = '';
      if (err) {
        mess = err;
      } else {
        mess = res.msg;
      }
      wx.showToast({
        title: mess,
        icon: 'none',
        duration: 2000
      })
    })
    this.beginTimer();
  },
  beginTimer: function () {
    var Timers = null;
    this.setData({
      showverification: '',
      count: 60,
      showtime: '60s'
    })
    var that = this;
    //如果定时器已经器动了
    if (!Timers) {
      Timers = setInterval(function () {
        var count = that.data.count - 1;
        that.setData({
          showtime: count + "s",
          Timers: Timers,
          count: count
        })
        if (count <= 0) {
          clearInterval(Timers)
          that.setData({
            count: 60,
            msg: '再次发送',
            showtime: ''
          })
        }
      }, 1000);
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})